import java.util.Scanner;
import java.util.Stack;

public class Solution {
    public int evalRPN(String[] tokens){
        Stack<Integer> stack = new Stack<>();
        int len = tokens.length;
        for (int i = 0; i < len; i++) {//遍历字符串数组
            String str = tokens[i];
            if(!isOperator(str)){
                Integer num = Integer.valueOf(str);//将字符转化为数字
                stack.push(num);
            }else{//如果是运算符，则栈顶两个元素出栈
                Integer num1 = stack.pop();
                Integer num2 = stack.pop();
                switch (str){
                    case "+":
                        stack.push(num2+num1);
                        break;
                    case"-":
                        stack.push(num2-num1);
                        break;
                    case"*":
                        stack.push(num2*num1);
                        break;
                    case"/":
                        stack.push(num2/num1);
                        break;
                }
            }
        }
        return stack.pop();
    }

    private boolean isOperator(String val){//先判断字符串是数字还是运算符
        if(val.equals("+") || val.equals("-") || val.equals("*") || val.equals("/")){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int len = in.nextInt();
            in.nextLine();
            String[] tokens = in.nextLine().split("\\s+");
            Solution solution = new Solution();
            int result = solution.evalRPN(tokens);
            System.out.println(result);
        }
    }
}
